<!-- 扫码核销页面 pages/verify/scan.vue -->
<template>
  <view class="scan-container">
    <view class="scan-tips">
      <text>将核销码放入框内即可自动扫描</text>
      <uni-icons type="scan" size="48" color="#fff" />
    </view>
  </view>
</template>

<script setup>
// import { onShow } from '@dcloudio/uni-app'
import {onMounted} from 'vue'

onMounted(() => {
  handleScan()
})

const handleScan = async () => {
  try {
    const res = await uni.scanCode({
      onlyFromCamera: true,
      scanType: ['qrCode']
    })
    
    uni.redirectTo({
      url: `/pages/Verification_code/Verification_code?code=${encodeURIComponent(res.result)}`
    })
    
  } catch (error) {
    if (error.errMsg !== 'scanCode:fail cancel') {
      uni.showToast({ title: '扫码失败', icon: 'none' })
	  uni.navigateBack()
    }
  }
}
</script>

<style lang="scss" scoped>
.scan-container {
  height: 100vh;
  background: rgba(0,0,0,0.9);
  display: flex;
  justify-content: center;
  align-items: center;

  .scan-tips {
    text-align: center;
    color: #fff;
    
    text {
      display: block;
      margin-bottom: 32rpx;
      font-size: 32rpx;
      opacity: 0.8;
    }
    
    .uni-icons {
      display: block;
      margin: 0 auto;
      padding: 16rpx;
      background: rgba(255,255,255,0.1);
      border-radius: 50%;
    }
  }
}
</style>